﻿[assembly: WebActivator.PreApplicationStartMethod(typeof(Agro.Web.App_Start.NinjectMVC3), "Start")]
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(Agro.Web.App_Start.NinjectMVC3), "Stop")]

namespace Agro.Web.App_Start
{
    using Microsoft.Web.Infrastructure.DynamicModuleHelper;
    using Ninject;
    using Agro.Services;
    using Ninject.Web.Mvc;

    public class NinjectMVC3
    {
        private static readonly Bootstrapper bootstrapper = new Bootstrapper();

        public static void Start()
        {
            DynamicModuleUtility.RegisterModule(typeof(OnePerRequestModule));
            DynamicModuleUtility.RegisterModule(typeof(HttpApplicationInitializationModule));
            bootstrapper.Initialize(CreateKernel);
        }

        /// <summary>
        /// Stops the application.
        /// </summary>
        public static void Stop()
        {
            bootstrapper.ShutDown();
        }

        /// <summary>
        /// Creates the kernel that will manage your application.
        /// </summary>
        /// <returns>The created kernel.</returns>
        private static IKernel CreateKernel()
        {
            var kernel = new StandardKernel();
            RegisterServices(kernel);
            return kernel;
        }

        private static void RegisterServices(IKernel kernel)
        {
            //操作功能权限
            kernel.Bind<IActionService>().To<ActionService>().InRequestScope();

            //系统消息
            kernel.Bind<IMessageService>().To<MessageService>().InRequestScope();
            //系统通知
            kernel.Bind<INoticeService>().To<NoticeService>().InRequestScope();
            //组织机构
            kernel.Bind<IOrganizationService>().To<OrganizationService>().InRequestScope();
            //菜单
            kernel.Bind<IMenuService>().To<MenuService>().InRequestScope();
            //用户
            kernel.Bind<IUserService>().To<UserService>().InRequestScope();
            //角色
            kernel.Bind<IRoleService>().To<RoleService>().InRequestScope();
            //登录
            kernel.Bind<ILogonService>().To<LogonService>().InRequestScope();
            //报表
            kernel.Bind<IReportService>().To<ReportService>().InRequestScope();
            //分析
            kernel.Bind<IReportAnalyse>().To<ReportAnalyse>().InRequestScope();
            //查询
            kernel.Bind<IReportSearch>().To<ReportSearch>().InRequestScope();
            //文件管理
            kernel.Bind<IFileService>().To<FileService>().InRequestScope();


            //执行sql
            kernel.Bind<IExecSqlService>().To<ExecSqlService>().InRequestScope();
            //报表默认上报日期
            kernel.Bind<ISbrqService>().To<SbrqService>().InRequestScope();
            //报表状态管理
            kernel.Bind<IBbztService>().To<BbztService>().InRequestScope();
            //报表默认上报日期
            kernel.Bind<IBbsService>().To<BbsService>().InRequestScope();

            kernel.Bind<IPermissionService>().To<PermissionService>().InRequestScope();
        }
    }
}
